#include<bits/stdc++.h>
using namespace std;
#define int long long
#define llg long long
#define sig signed
#define rg register
#define sht short
#define endl "\n"
int t,n,m,k,a[1005],d[1055][1055],q[1005];
inline int check(int x){
    int r=log2(x);
    queue<int>q[20];
    for(int i=1;i<=x;i++)q[0].push(a[i]);
    for(int i=1;i<=r;i++){
        for(int j=1;j<=(1<<r-i);j++){
            int x=q[i-1].front();
            q[i-1].pop();
            int y=q[i-1].front();
            q[i-1].pop();
            if(d[i][j]==0){
                if(x>=i)q[i].push(x);
                else q[i].push(y);
            }else{
                if(y>=i)q[i].push(y);
                else q[i].push(x);
            }
        }
    }
    return q[r].front();
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>q[i];
    while((1<<k)<n)k++;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=(1<<k-i);j++){
            char c;
            cin>>c;
            d[i][j]=c-'0';
        }
    }
    int x[5];
    cin>>t>>x[0]>>x[1]>>x[2]>>x[3];
    for(int i=1;i<=n;i++)a[i]=a[i]^x[i%4];
    for(int i=1;i<=m;i++)q[i]*=check(q[i]);
    x[0]=0;
    for(int i=1;i<=m;i++){
        x[0]^=q[i];
    }
    cout<<x[0];
    return 0;
}
